import Vue from 'vue'
//导入vue-router
import VueRouter from 'vue-router'
//导入login
import login from '@/views/login/login.vue'
import layout from '@/views/layout/layout.vue'
import chart from '@/views/layout/chart/chart.vue'
import user from '@/views/layout/user/user.vue'
import question from '@/views/layout/question/question.vue'
import business from '@/views/layout/business/business.vue'
import subject from '@/views/layout/subject/subject.vue'


//注册vue-routeruser
Vue.use(VueRouter)

//实例化vue-router
const router = new VueRouter({
    routes: [{
            path: '/',
            redirect: './login'
        },
        {
            path: '/login',
            component: login
        },
        {
            path: '/layout',
            component: layout,
            redirect: "/layout/subject",
            children: [{
                    path: '/layout/chart',
                    component: chart,
                    //meta:路由元
                    meta: {
                        title: '数据概览'
                    }
                },
                {
                    path: 'user', // 不写/是相对于自己父级的地址
                    component: user,
                    meta: {
                        title: '用户列表'
                    }
                },
                {
                    path: 'qusetion',
                    component: question,
                    meta: {
                        title: '题库列表'
                    }
                },
                {
                    path: 'business',
                    component: business,
                    meta: {
                        title: '企业列表'
                    }
                },
                {
                    path: 'subject',
                    component: subject,
                    meta: {
                        title: '学科列表'
                    }
                }
            ]
        }
    ]
})

//1.装包npm i nprogress
//2.导入Nprogress
import Nprogress from 'nprogress'
import "nprogress/nprogress.css"
//离开时拦截 路由前置守卫
router.beforeEach((to, from, next) => {
    Nprogress.start()
    next()
})
//进入后拦截 路由后置守卫
router.afterEach((to, from) => {
    Nprogress.done()
    console.log('to', from);
    console.log('from', from);
    // document.getElementById('title').innerText = to.meta.title
    document.title = to.meta.title
})

//输出router
export default router